package com.momo.hr.service;

import com.momo.hr.bean.Department;
import com.momo.hr.mapper.DepartmentMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DepartmentService {

    @Autowired
    DepartmentMapper departmentMapper;

    /**
     * 这里采用了SQL递归的方式进行，嵌套查询
     * @return List<Department>
     */
    public List<Department> getAllDepartments(){
        return this.departmentMapper.getAllDepartmentsByParentId(-1);
    }

    public void addDepartment(Department department) {
        department.setEnabled(true);//设置enabled为true
        this.departmentMapper.addDep(department);
    }

    public void deleteDepById(Department dep) {
        this.departmentMapper.deleteDepById(dep);

    }
    //
    public List<Department> getAllDepartmentsWithOutChildren() {
        return this.departmentMapper.getAllDepartmentsWithOutChildren();
    }
}
